﻿using AutoMapper;
using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Write.API.Command.RoleMenuCommand;
using MediatR;

namespace B.S.BaseData.Write.API.CommandHandler.RoleMenuHandler
{
    public class DelRangeRoleMenuHandler : IRequestHandler<DelRangeRoleMenuCommand, APIResult<int>>
    {
        private readonly IBaseRepository<RoleMenu> rmRep;
        private readonly IMapper mapper;

        public DelRangeRoleMenuHandler(IBaseRepository<RoleMenu> rmRep,IMapper mapper)
        {
            this.rmRep = rmRep;
            this.mapper = mapper;
        }
        public Task<APIResult<int>> Handle(DelRangeRoleMenuCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list=rmRep.GetAll().Where(x=>x.RoleId==request.RoleId).ToList();
            rmRep.DeleteRemove(list);
            result.Code = APIEnum.Success;
            result.Msg = "删除成功";
            result.Data = 1;
            return Task.FromResult(result);
        }
    }
}
